package com.hp.web.controller.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hp.common.annotation.Log;
import com.hp.common.core.controller.BaseController;
import com.hp.common.core.domain.AjaxResult;
import com.hp.common.core.page.TableDataInfo;
import com.hp.common.enums.BusinessType;
import com.hp.common.utils.poi.ExcelUtil;
import com.hp.framework.util.ShiroUtils;
import com.hp.quartz.domain.SysJob;
import com.hp.quartz.task.CarInfoTask;
import com.hp.system.domain.*;
import com.hp.system.service.CarTypeService;
import com.hp.system.service.DestbationCityService;
import com.hp.system.service.PassInfoService;
import com.hp.system.utils.JSONInfoUtil;
import com.hp.quartz.service.ISysJobService;
import com.hp.system.service.IdentifyInfoServce;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/system/identify")
public class IdentifyInfoController extends BaseController {

    @Autowired(required = false)
    private static IdentifyInfo identifyInfo;
    @Autowired
    private IdentifyInfoServce identifyInfoServce;
    @Autowired
    private ISysJobService sysJobService;
    @Autowired
    private DestbationCityService destbationCityService;
    @Autowired
    private CarTypeService carTypeService;
    @Autowired
    private PassInfoService passInfoService;
    @Autowired
    private CarInfoTask carInfoTask;

    private String prefix = "system/identify";

    @RequiresPermissions("system:identify:view")
    @GetMapping()
    public String identify(){
        return prefix+"/identify";
    }

    @RequiresPermissions("system:identify:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IdentifyInfo identifyInfo){
        startPage();
        List<IdentifyInfo> list = identifyInfoServce.selectByIdentify(identifyInfo);
        return getDataTable(list);
    }

    @RequiresPermissions("system:identify:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap){
        IdentifyInfo identifyInfo = identifyInfoServce.selectById(id);
        mmap.put("identifyInfo",identifyInfo);
        return prefix+"/edit";

    }

    @RequiresPermissions("system:identify:city")
    @PostMapping("/city")
    @ResponseBody
    public List<DestbationCity> getCity(Integer destId){
        List<DestbationCity> list = destbationCityService.showDestCity(destId);
        return list;
    }

    @RequiresPermissions("system:identify:type")
    @PostMapping("/type")
    @ResponseBody
    public List<CarType> getType(Integer belongid){
        List<CarType> list = carTypeService.showType(belongid);
        return list;
    }

    @RequiresPermissions("system:identify:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PassInfo passInfo) throws Exception {
        passInfo.setIndate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(JSONInfoUtil.getTime()));
        return toAjax(passInfoService.dealInfo(passInfo));
    }

    @Log(title = "进出记录", businessType = BusinessType.EXPORT)
    @RequiresPermissions("system:identify:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IdentifyInfo identifyInfo){
        List<IdentifyInfo> list = identifyInfoServce.selectByIdentify(identifyInfo);
        ExcelUtil<IdentifyInfo> util = new ExcelUtil<IdentifyInfo>(IdentifyInfo.class);
        return util.exportExcel(list, "识别记录");
    }

    @RequiresPermissions("system:identify:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Integer id, ModelMap mmap)
    {
        System.out.println("进入控制器");
        mmap.put("passInfo", passInfoService.showPassInfoByIdentifyId(id));
        return prefix + "/detail";
    }
}
